//
//  DateCircle.swift
//  GOFM
//
//  Created by siri on 2024/10/21.
//  Copyright © 2024 Glad. All rights reserved.
//

import SwiftUI

struct DateCircle: View {
  
      var stateCode:Int // 0 代表是今天 1 代表其他日期
      var index: Int //当前传入的日期
      @EnvironmentObject var output:MyMeetingViewModel.Output // 月会议信息
      @Binding var selectDate:Int  // 点击的日期
    
       var body: some View {
           VStack(spacing: 2) {
               
               if (stateCode == 0) {
                   // 今天日期的样式
                   Text("今").font(Font.g_font_body_medium16).foregroundColor(  selectDate == index ? Color.g_color_font_white : Color.g_color_theme)
               }else {
                   //  其他日期的样式
                   Text("\(index)").foregroundColor(selectDate == index ? Color.g_color_font_white:Color.g_color_font_primary )
               }
               
               // 是否有月会议信息
               if output.appointMonthMeetingsInfoList.count > 0{
                   ForEach(0..<output.appointMonthMeetingsInfoList.count,id:\.self) {
                       i  in
                       // 判断当前日期是否等于月会议的日期
                       if Int( (output.appointMonthMeetingsInfoList[i].appointDate?.split(separator: "-").last)!) == index {
                           HStack (spacing:2) {
                               Circle().foregroundColor(Color(hex: "#5ac8fa")).frame(width:5,height:  5)
                               Circle().foregroundColor(Color(hex: "#f8c900")).frame(width:5,height:  5)
                           }
                           
                       }
                   }
               }
               
           }.frame(width: 35,height: 35).background(
            // 点击日期样式改变
            stateCode == 0 ? Circle().foregroundColor(selectDate == index ?Color.g_color_theme: Color.g_color_bg_grey) :  Circle().foregroundColor(selectDate == index ?  Color.g_color_theme :  Color.g_color_bg_white)
           )
           .onTapGesture {
               selectDate = index
           }
       }
}

//struct DateCircle_Previews: PreviewProvider {
//    static var previews: some View {
//        DateCircle()
//    }
//}
